<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('scene list')" />
	<th:block th:include="include :: layout-latest-css" />
	<th:block th:include="include :: ztree-css" />
</head>
<body class="gray-bg">
	<div class="container-div">
		<div class="row">
			<div class="col-sm-12 search-collapse">
				<form id="form">
					<input type="hidden" id="pageFlag" name="pageFlag" th:value="${scene.pageFlag}"/>
					<div class="select-list">
						<ul>
							<li class="select-time">
								<label>考核日期： </label>
								<input type="text" class="" id="dayId" name="dayId" th:value="${scene.dayId}"/>
							</li>
							<li>
								被考核单位：
								<select name="dept.deptId" id="dept.deptId">
									<option value="">--请选择--</option>
									<option th:each="dept : ${deptList}" th:text="${dept.deptName}" th:value="${dept.deptId}"
										th:selected="${scene.dept.deptId == dept.deptId}" />
								</select>
							</li>
							<li th:if="${'QUERY' != scene.pageFlag}">
								状态：
								<select name="status" id="status" th:with="dicts=${@dict.getType('rate_scene_status')}">
									<option value="">--请选择--</option>
									<option th:each="dict : ${dicts}" th:text="${dict.dictLabel}" th:value="${dict.dictValue}"
										th:selected="${scene.status == dict.dictValue}"></option>
								</select>
							</li>
							<li>
								<a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
								&nbsp;&nbsp;
								<a style="margin-left:20px;" class="btn btn-danger btn-rounded btn-sm" onclick="add()"
									th:if="${'SUBMIT' == scene.pageFlag}">
									<i class="fa fa-plus"></i> 新增
								</a>
								<a style="margin-left:20px;" class="btn btn-warning btn-rounded btn-sm" onclick="doExport()"
									th:if="${'CHECK30' == scene.pageFlag}">
									<i class="fa fa-download"></i> 导出
								</a>
							</li>
						</ul>
					</div>
				</form>
			</div>
			<div class="btn-group-sm" id="toolbar" role="group"
				th:if="${('CHECK10' == scene.pageFlag || 'CHECK20' == scene.pageFlag)}">
				<a class="btn btn-danger" onclick="batchSubmitCheck()">
					<i class="fa fa-check"></i> 批量审批
				</a>
				&nbsp;&nbsp;&nbsp;&nbsp;
				<select id="checkResult" class="" style="width:150px; height:30px;">
					<option value="">请选择审核结果</option>
					<option value="APPROVED">通过</option>
					<option value="REJECTED">拒绝</option>
				</select>
			</div>
			<div class="col-sm-12 select-table table-striped">
				<table id="bootstrap-table"></table>
			</div>
		</div>
	</div>
	
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: layout-latest-js" />
	<th:block th:include="include :: datetimepicker-css" />
	<th:block th:include="include :: datetimepicker-js" />
	<script th:inline="javascript">
		var prefix = ctx + "rate/scene";
		var statusDict = [[${@dict.getType('rate_scene_status')}]];
		var pageFlag = [[${scene.pageFlag}]];

		$(function() {
			$("#dayId").datetimepicker({
				format: 'yyyy-mm-dd',
				autoclose: true,
				startView: 2,
				minView: 2
			});
			list();
		});

		function list() {
			var cols = [];
			cols.push({
				checkbox: true
			});
			cols.push({
				field: 'id',
				visible: false
			});
			cols.push({
				field: 'dayId',
				align: 'center',
				title: '考核日期',
				width: '10%',
			});
			cols.push({
				field: 'person1',
				align: 'center',
				title: '上报人员',
				formatter: function(value, row, index) {
					return row.person1 + "<br/>" + row.person2;
				}
			});
			cols.push({
				field: 'dept.deptName',
				align: 'center',
				title: '考核单位'
			});
			cols.push({
				field: 'content1',
				align: 'left',
				title: '考核内容',
				width: '15%',
			});
			/**
			cols.push({
				field: 'content2',
				align: 'left',
				title: '考核依据'
			});
			**/
			cols.push({
				field: 'content3',
				align: 'left',
				title: '考核形式',
				width: '10%',
			});
			cols.push({
				field: 'score',
				align: 'center',
				title: '奖罚情况'
			});
			cols.push({
				field: 'attach.id',
				align: 'center',
				title: '截图',
				formatter: function(value, row, index) {
					if (!value) {
						return null;
					}
					return '<a href="javascrpit:void(0);" onclick="viewPic(\'' + value + '\')">查看</a>';
				}
			});
			cols.push({
				field: 'status',
				align: 'center',
				title: '当前状态',
				width: '10%',
				formatter: function(value, row, index) {
					return $.table.selectDictLabel(statusDict, value);
				}
			});
			cols.push({
				field: 'createUser.userName',
				align: 'center',
				title: '提交人'
			});
			/**
			cols.push({
				field: 'createTime',
				align: 'center',
				title: '提交时间'
			});
			**/
			cols.push({
				field: 'fgldChecker.userName',
				align: 'center',
				title: '值班领导'
			});
			cols.push({
				title: '操作',
				align: 'center',
				width: '25%',
				formatter: function(value, row, index) {
					var status = row.status;
					
					var actions = [];
					if ("SUBMIT" == pageFlag) {
						if ("DRAFT" == status || "REJECTED" == status) {
							actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="edit(\'' + row.id + '\', \'0\')"><i class="fa fa-edit"></i>编辑</a> ');
							//actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="submitToCheck(\'' + row.id + '\')"><i class="fa fa-check"></i>提交审核</a> ');
							actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="remove1(\'' + row.id + '\')"><i class="fa fa-times"></i>删除</a> ');
						} else {
							actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" disabled="disabled"><i class="fa fa-edit"></i>编辑</a> ');
							//actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" disabled="disabled"><i class="fa fa-check"></i>提交审核</a> ');
							actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" disabled="disabled"><i class="fa fa-times"></i>删除</a> ');
						}
						if ("CHECK10" == status) {
                            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="cancelSubmit(\'' + row.id + '\')"><i class="fa fa-caret-square-o-left"></i>撤回</a> ');
                        } else {
                            actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" disabled="disabled"><i class="fa fa-caret-square-o-left"></i>撤回</a> ');
                        }
						actions.push('<a class="btn btn-info btn-xs" href="javascript:void(0)" onclick="copy(\'' + row.id + '\', \'0\')"><i class="fa fa-copy"></i>复制</a> ');
					} else {
						var text;
						var canEdit = "0";
                        var canCancelCheck = "0";
                        if (pageFlag == "CHECK10") {
                            text = "领导审核";
                            if ("CHECK20" == status) {
                            	canCancelCheck = "1";
                            }
                            if ("CHECK10" == status) {
                            	canEdit = "1";
                            }
                        } else if (pageFlag == "CHECK20") {
                            text = "监狱长审核";
                            if ("APPROVED" == status) {
                            	canCancelCheck = "1";
                            }
                            if ("CHECK20" == status) {
                            	canEdit = "1";
                            }
                        } else if (pageFlag == "CHECK30") {
                        	canEdit = "1";
                        }
                        
                        if (text) {
                            if (pageFlag == status) {
                                actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="check(\'' + row.status + '\', \'' + row.id + '\')"><i class="fa fa-check"></i>' + text + '</a> ');
                            } else {
                                actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" disabled="disabled"><i class="fa fa-check"></i>' + text + '</a> ');
                            }

                            if (canCancelCheck == "1") {
                                actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" onclick="cancelCheck(\'' + pageFlag + '\', \'' + row.id + '\')"><i class="fa fa-caret-square-o-left"></i>' + text + '-撤销</a> ');
                            } else {
                                actions.push('<a class="btn btn-warning btn-xs" href="javascript:void(0)" disabled="disabled"><i class="fa fa-caret-square-o-left"></i>' + text + '-撤销</a> ');
                            }
                        }
                        
                        if (canEdit == "1") {
                        	actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="edit(\'' + row.id + '\', \'1\')"><i class="fa fa-edit"></i>编辑</a> ');
                        	actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" onclick="remove1(\'' + row.id + '\')"><i class="fa fa-times"></i>删除</a> ');
                        } else {
                        	actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" disabled="disabled"><i class="fa fa-edit"></i>编辑</a> ');
                        	actions.push('<a class="btn btn-danger btn-xs" href="javascript:void(0)" disabled="disabled"><i class="fa fa-times"></i>删除</a> ');
                        }
					}
					
					actions.push('<a class="btn btn-success btn-xs" href="javascript:void(0)" onclick="view(\'' + row.id + '\')"><i class="fa fa-query"></i>查看</a> ');
					return actions.join('');
				}
			});
			
			var options = {
				url: prefix + "/list",
				exportUrl: prefix + "/export",
				modalName: "现场考核",
				uniqueId: "id",
				columns: cols
			};
			$.table.init(options);
		}
		
		function add() {
			$.modal.openFull("新增",
					prefix + "/add?pageFlag=ADD");
		}
		function edit(id, reserveStatus) {
			$.modal.openFull("修改",
					prefix + "/edit?id=" + id + "&pageFlag=EDIT&reserveStatus=" + reserveStatus);
		}
		function copy(id) {
			$.modal.openFull("新增",
					prefix + "/add?pageFlag=ADD&id=" + id);
		}
		/*
		function submitToCheck(id) {
			$.modal.confirm("确认要提交该条记录吗?", function() {
				var url = prefix + "/submitToCheck";
				var data = {"timestamp": new Date().getTime(), "id": id};
				$.operate.submit(url, "post", "json", data);
			});
		}*/
		function cancelSubmit(id) {
			$.modal.confirm("确认要撤回该条记录吗?", function() {
				var url = prefix + "/cancelSubmit";
				var data = {"timestamp": new Date().getTime(), "id": id};
				$.operate.submit(url, "post", "json", data);
			});
		}
		/*
		function batchCancel() {
			var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
			if (rows.length == 0) {
				$.modal.alertWarning("请至少选择一条记录");
				return;
			}
			
			$.modal.confirm("确认要将选中的【" + rows.length + "】条数据批量撤回吗?", function() {
				var url = prefix + "/batchCancel";
				var data = { "ids": rows.join(), "pageFlag": pageFlag};
				$.operate.submit(url, "post", "json", data);
			});
		}
		*/
		function check(pageFlag, id) {
            $.modal.openFull("审批",
                prefix + "/edit?id=" + id + "&pageFlag=" + pageFlag);
        }
        function cancelCheck(pageFlag, id) {
            $.modal.confirm("确认要撤销审批该条记录吗?", function() {
                var url = prefix + "/cancelCheck";
                var data = {"timestamp": new Date().getTime(), "id": id, "pageFlag": pageFlag};
                $.operate.submit(url, "post", "json", data);
            });
        }
		function view(id) {
			$.modal.openFull("查看",
					prefix + "/edit?id=" + id + "&pageFlag=VIEW");
		}
		function remove1(id) {
			$.modal.confirm("确认要删除该条记录吗?", function() {
				var url = prefix + "/delete/" + id;
				var data = {"timestamp": new Date().getTime()};
				$.operate.submit(url, "post", "json", data);
			});
		}
		/*
		function batchSubmitToCheck() {
			var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
			if (rows.length == 0) {
				$.modal.alertWarning("请至少选择一条记录");
				return;
			}
			
			$.modal.confirm("确认要将选中的【" + rows.length + "】条数据批量提交审核吗?", function() {
				var url = prefix + "/batchSubmitToCheck";
				var data = { "ids": rows.join(), "pageFlag": pageFlag};
				$.operate.submit(url, "post", "json", data);
			});
		}
		*/
		function batchSubmitCheck() {
			var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
			if (rows.length == 0) {
				$.modal.alertWarning("请至少选择一条记录");
				return;
			}
			
			var checkResult = $("#checkResult").val();
			if (checkResult == null || checkResult == "") {
				$.modal.alertWarning("请选择审核结果。");
				return;
			}
			
			$.modal.confirm("确认要将选中的【" + rows.length + "】条数据批量审核通过吗?", function() {
				var url = prefix + "/batchSubmitCheck";
				var data = { "ids": rows.join(), "pageFlag": pageFlag, "checkResult": checkResult};
				$.operate.submit(url, "post", "json", data);
			});
		}
		
		function viewPic(id) {
			window.open(ctx + "rate/attach/viewImg?id="+id);
		}
		
		function doExport() {
			if ($("#dayId").val() == '') {
				$.modal.alertWarning("请选择日期！");
				return false;
			}
			$.table.exportExcel();
		}
	</script>
</body>
</html>